package com.ld.poetry.export;

import com.alibaba.excel.write.metadata.WriteSheet;
import com.foxchen.offline.task.ExportHandler;
import com.ld.poetry.config.AppConfigs;
import com.ld.poetry.entity.ResourceConfig;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Component("qiniu_upload-export")
public class QiNiuUploadExport extends ExportHandler {
    @Resource
    private AppConfigs appConfigs;

    @Override
    public Pair<Long, Long> getTotalAndSingleBatch(Integer integer) {
        String param = getTaskInfo().getParam();
        List<ResourceConfig> allResourceConfig = appConfigs.getAllResourceConfig();
        long dataCount = allResourceConfig.stream().filter(config -> config.getId().equals(param)).count();

        return Pair.of(dataCount, BigDecimal.ONE.longValue());
    }

    @Override
    public List<WriteSheet> getSheetList() {
        List<WriteSheet> sheetList = new ArrayList<>();
        WriteSheet sheet = new WriteSheet();
        sheet.setSheetName("七牛配置");
        sheet.setSheetNo(1);
        sheet.setClazz(ResourceConfig.class);
        sheetList.add(sheet);
        return sheetList;
    }

    @Override
    public List<?> pageGetSheetData(Integer sheetNo, Long pageNum, Long pageSize) {
        return appConfigs.getAllResourceConfig().stream().filter(config -> config.getId().equals(getTaskInfo().getParam())).collect(Collectors.toList());
    }
}
